package com.txx.controller;

import com.txx.pojo.GoodsCategory;
import com.txx.service.GoodsCategoryService;
import com.txx.vof.GoodsCategoryForm;
import com.txx.vof.UserForm;
import com.txx.vor.PageResult;
import com.txx.vor.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: zgc
 * @Date: 2021/5/19 9:38
 */
@RestController
@CrossOrigin
@RequestMapping("/goodsCategory")    //抽取公共的请求
public class GoodsCategoryController {


    @Autowired
    private GoodsCategoryService goodsCategoryService;
    /**
     * 需求: 进行分页查询
     * URL地址:  /user/list
     * 请求参数: 使用PageResult对象接收
     * 请求返回值: SysResult对象
     * 请求类型: get请求
     */
    @GetMapping("/list")
    public SysResult getGoodsCategory(GoodsCategoryForm data){//只有3个参数

         PageResult pageResult = goodsCategoryService.getGoodsCategory(data);
        //携带所有的数据返回
        return SysResult.success(pageResult);
    }

    @PostMapping("/insert")
    public SysResult insert(@RequestBody GoodsCategory goodsCategory)
    {
        return SysResult.success(goodsCategoryService.insert(goodsCategory));
    }

    @GetMapping("/{id}")
    public SysResult getCategoryById(@PathVariable int id)
    {
        return SysResult.success(goodsCategoryService.getCategoryById(id));
    }

    @PutMapping("/update")
    public SysResult getCategoryById(@RequestBody GoodsCategory goodsCategory)
    {
        return SysResult.success(goodsCategoryService.Update(goodsCategory));
    }

    @DeleteMapping("/{id}")
    public SysResult delete(@PathVariable int id)
    {
        return SysResult.success( goodsCategoryService.delete(id));
    }

}
